<%--
  Created by IntelliJ IDEA.
  User: 郑自航
  Date: 2018/7/4
  Time: 11:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ServerInfo</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="${basePath}/layui/css/layui.css">
    <script type="text/javascript" src="${basePath}/js/plugin/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="${basePath}/js/plugin/jquery.i18n.properties.min.js"></script>
    <script src="${basePath}/layui/layui.js"></script>
</head>

<body class="page-body">
<div class="layui-inline"></div>
<div id="content">
    <form class="layui-form">
        <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text">服务名称:</label>
                        <div class="layui-input-inline">
                            <input name="serverName" id="serverName_inputId" lay-verify="" placeholder="服务名称" autocomplete="true" class="layui-input"
                                   type="text">
                        </div>
                    </div>

                     <div class="layui-inline">
                         <label class="layui-form-label l-lab-text">服务价格:</label>
                         <div class="layui-input-inline">
                             <input name="price" id="price_inputId" lay-verify="" placeholder="服务价格" autocomplete="true" class="layui-input"
                                    type="number">
                         </div>
                     </div>

                        <div class="layui-inline">
                            <label class="layui-form-label l-lab-text">服务类型:</label>
                            <div class="layui-input-inline">
                                <select name="type" id="type_selectId" lay-search="">
                                    <option value="" class="l-lab-text">All</option>
                                </select>
                            </div>
                        </div>

                    <div class="layui-inline">
                        <label class="layui-form-label l-lab-text">创建时间:</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" id="createTimeBegDate" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        </div>
                        <div class="layui-form-mid layui-word-aux"> -</div>
                        <div class="layui-input-inline">
                            <input class="layui-input" id="createTimeEndDate" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        </div>
                    </div>

            <div class="layui-inline">
                <div class="layui-inline">
                    <button type="button" class="layui-btn l-lab-text" id="search" data-type="search" onclick="tableReload(1)">Search</button>
                    <button type="button" class="layui-btn layui-btn-warm l-lab-text" onclick="addOrUpdateServerInfo()">Add</button>
                    <button type="button" class="layui-btn layui-btn-danger l-lab-text" id="btn_del">Delete</button>
                    <button type="reset" class="layui-btn layui-btn-primary l-lab-text">Rest</button>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="ibox-content">
    <table class="table-hide" id="demoTable" lay-data="{id: 'idApply'}" lay-filter="Apply"></table>
</div>
<script src="${basePath}/js/i18n.js"></script>
<script src="${basePath}/js/common.js"></script>
<script src="${basePath}/js/DateFormate.js"></script>
</body>
<script type="text/html" id="titleTpl4">
    {{# if(!(d.createTime)){ }}
    {{# } else { }}
    {{formatDateTime(new Date(d.createTime))}}
    {{# } }}
</script>
<script type="text/html" id="titleTpl5">
    {{# if(!(d.updateTime)){ }}
    {{# } else { }}
    {{ formatDateTime(new Date(d.updateTime)) }}
    {{# } }}
</script>
<script type="text/html" id="titleTpl_begTime">
    {{# if(!(d.begTime)){ }}
    {{# } else { }}
    {{ formatDateTime(new Date(d.begTime)) }}
    {{# } }}
</script>
<script type="text/html" id="titleTpl_endTime">
    {{# if(!(d.endTime)){ }}
    {{# } else { }}
    {{ formatDateTime(new Date(d.endTime)) }}
    {{# } }}
</script>
            <script type="text/html" id="titleTpl_type">
            {{#   if(!(d.type)&&d.type!=0){          }}
            {{#   } else {        }}
            {{#      var data = $("#type_selectId").data('type_selectId'); }}
            {{#      for (var opt in data) {             }}
            {{#          if( data[opt].value == d.type){     }}
            {{                 data[opt].label       }}
            {{#                 break;       }}
            {{#          }       }}
            {{#       }       }}
            {{#   }       }}
            </script>
            <script type="text/html" id="titleTpl_sort">
            {{#   if(!(d.sort&&d.type!=0)){          }}
            {{#   } else {        }}
            {{#      var data = $("#sort_selectId").data('sort_selectId'); }}
            {{#      for (var opt in data) {             }}
            {{#          if( data[opt].value == d.sort){     }}
            {{                 data[opt].label       }}
            {{#                 break;       }}
            {{#          }       }}
            {{#       }       }}
            {{#   }       }}
            </script>
<script type="text/javascript">
    function addOrUpdateServerInfo(id) {
        var layer = window.parent.layer;
        top.addServerInfo_layer = layer.open({
            type: 2,
            title: top._loadText(id?'Update':'Add')+" "+top._loadText('ServerInfo'),
            shadeClose: true,
            shade: false,
            // maxmin: true, //开启最大化最小化按钮
            area: ['460px', '600px'],
            content: 'serverInfoEdit.page' + (id ? "?id=" + id : ''),
            end:tableReload
        });
        return false;
    }
    var table;
    //提交查询
    function tableReload(pageNO) {
        var queryParams;
        queryParams=$(".layui-form").serializeJson();
        // top.myLayer.alert(queryParams);
        // debugger
        table.reload('idApply', {
            where: queryParams,
            page: {
                curr: pageNO?pageNO:1    //重新从第 n 页开始
            }
        });
        //自动切换语言
        doTranslateTable();
        return false;
    }
    $(function () {
        /*初始化下拉选*/
        var types=['serverInfo_type','serverInfo_sort'];
        //批量初始化下拉选
        initBatchSelect(types,null);

        // debugger
        // 自动切换语言
        doTranslate();
        //注意：导航 依赖 element 模块，否则无法进行功能性操作
        layui.use('element', function () {
            var element = layui.element;
            element.init();
//             element.init('breadcrumb');
//             element.render('nav');
//             element.render('tab');
//             //…
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            var ids=['createTimeBegDate','createTimeEndDate'
                    ,'begTimeBegDate','begTimeEndDate'
                    ,'endTimeBegDate','endTimeEndDate'];
            //批量初始化
            initBatchDate(laydate,ids);
        });

        layui.use('table', function () {
            table = layui.table;
            var tableIns = table.render({
                elem: '#demoTable',
                url: '${basePath}/server/serverInfo/findServerInfoList.do',
                id: 'idApply',
                cellMinWidth: 120,
                page: {
                    limit:20
                },
                method: "post",
                done: function (res, curr, count) {
                },
                cols: [
                    [{
                        field: 'id',
                        type: 'checkbox',
                        title: 'ID',
                        sort: true,
                        fixed: 'left'
                    },
                    {
                        title: '<span  class="l-lab-text">Index</span>',
                        templet: '#indexTpl',
                        width: 60,
                        align: 'center'
                    },
                        {
                            field: 'serverName',
                            title: '<span  class="l-lab-text">服务名称</span>',
                            width: 120,
                            sort: true,
                            /*align: 'center'*/
                        },
                        {
                            field: 'type',
                            'title': '<span  class="l-lab-text">服务类型</span>',
                            width: 120,
                            sort: true,
                            templet: titleTpl_type //自定义模板
                        },
                        {
                            field: 'price',
                            'title': '<span  class="l-lab-text">服务价格</span>',
                            width: 120,
                            sort: true,
                        },
                        {
                            field: 'discounts',
                            'title': '<span  class="l-lab-text">优惠价格</span>',
                            width: 120,
                            sort: true,
                        },
                        // {
                        //     field: 'sort',
                        //     'title': '<span  class="l-lab-text">服务级别排序</span>',
                        //     width: 120,
                        //     sort: true,
                        //     templet: titleTpl_sort //自定义模板
                        // },
                        {
                            field: 'remakes',
                            title: '<span  class="l-lab-text">备注</span>',
                            width: 120,
                            sort: true,
                            /*align: 'center'*/
                        },
                        {
                            field: 'createUser',
                            title: '<span  class="l-lab-text">创建人</span>',
                            width: 120,
                            sort: true,
                            /*align: 'center'*/
                        },
                         {
                             field: 'createTime',
                             'title': '<span  class="l-lab-text">创建时间</span>',
                             width: 120,
                             sort: true,
                             templet: titleTpl4
                         },
                        {
                            field: 'updateUser',
                            title: '<span  class="l-lab-text">修改人</span>',
                            width: 120,
                            sort: true,
                            /*align: 'center'*/
                        },
                         {
                             field: 'updateTime',
                             'title': '<span  class="l-lab-text">修改时间</span>',
                             width: 120,
                             sort: true,
                             templet: titleTpl5
                         },
                        {
                            fixed: 'right',
                            title: '<span  class="l-lab-text">Operation</span>',
                            align: 'center',
                            width: 120,
                            toolbar: '#barTools'
                        }
                    ]
                ],
            });
            /*table.on('sort(idApply)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                debugger
            });*/
            //自动切换语言
            doTranslateTable();
            var $ = layui.$;
            layui.use('form', function () {
                var form = layui.form;
                //监听提交
                form.on('submit(sbumit)', function (data) {
                    // debugger
                    // top.layer.msg(JSON.stringify(data.field));
                    return false;
                })
            });
            //监听批量删除按钮
            $('#btn_del').on('click', function () {
                var checkStatus = table.checkStatus('idApply'); //获取选中的列
                if (checkStatus.data.length != 0) {
                    top.layer.confirm('确认是否删除', function (index) {
                        top.layer.close(index);
                        var chk_value=new Array();
                        for (var i = 0; i < checkStatus.data.length; i++) {
                            chk_value.push(checkStatus.data[i].id+'');
                        }
                        var param = {
                            "ids": chk_value
                        };
                        $.ajax({
                            type: "POST",
                            url: "${basePath}/server/serverInfo/deleteServerInfoByIds.do",
                            data: param,
                            traditional: true,//这里设置为true
                            success: function(){tableReload(checkStatus.data[0].page)}
                        });
                    });
                } else {
                    top.layer.msg("请选择至少一条数据");
                }

                return false;
            });

            //监听工具条
            table.on('tool()', function (obj) {
                debugger
                var data = obj.data;
                var checkStatus = table.checkStatus('idApply');
                console.log(checkStatus.data);
                if (obj.event === 'del') {
                    top.layer.confirm('确认是否删除', function (index) {
                        var param = {
                            "id": data.id
                        };
                        $.ajax({
                            type: "POST",
                            url: "${basePath}/server/serverInfo/deleteServerInfo.do",
                            data: param,
                            success: function (data) {
                                top.layer.msg(data.msg);
                            }
                        });
                        obj.del();
                        top.layer.close(index);
                    });
                } else if (obj.event === 'update') {
                    var data = obj.data;
                    addOrUpdateServerInfo(data.id);
                }
                return false;
            });
        });
    })
</script>
<script type="text/html" id="indexTpl">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script type="text/html" id="barTools">
    <a class="layui-btn layui-btn-primary layui-btn-xs l-lab-text" lay-event="update">{{top._loadText('Update')}}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs l-lab-text" lay-event="del">{{top._loadText('Delete')}}</a>
</script>

</html>